package com.example.xlzx.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.xlzx.entity.ContactUs;
import com.example.xlzx.entity.Post;
import com.example.xlzx.result.Result;
import com.example.xlzx.service.IContactUsService;
import com.example.xlzx.service.IPostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 帖子表 前端控制器
 * </p>
 *
 * @author 1
 * @since 2025-03-07
 */
@RestController
@Tag(name="帖子信息")
@RequestMapping("/xlzx")
public class PostController {
    @Autowired
    private IPostService postService;
    @Operation(summary = "新增帖子")
    @PostMapping("/insetPost")
    public Result<Boolean> insertPost(@RequestBody Post post) {
        return Result.ok(postService.save(post));
    }

    @Operation(summary = "根据id删除帖子")
    @DeleteMapping("/deletePost/{id}")
    public Result<Boolean> deletePost(@PathVariable Long id) {
        return Result.ok(postService.removeById(id));
    }

    @Operation(summary = "修改帖子")
    @PutMapping("/updatePost")
    public Result<Boolean> updatePost(@RequestBody Post post) {
        return Result.ok(postService.updatePostInfo(post));
    }

    @Operation(summary = "根据id查询联系帖子")
    @GetMapping("/getPostInfo/{id}")
    public Result<Post> getPostInfo(@PathVariable Long id) {
        return Result.ok(postService.getById(id));
    }

    @Operation(summary = "帖子分页查询")
    @GetMapping("/selectPost/page")
    public Result<Page<Post>> selectPost(@RequestParam int page, @RequestParam int size) {
        Page<Post> pageParam = new Page<>(page, size);
        return Result.ok(postService.page(pageParam));
    }
}
